<template>
<div id="userChangeAudit"></div>
</template>

<script>
import axios from "axios";
import {request} from "../../../../utils/request";
import checkPermission from "../../../../utils/permission";

export default {
  name: "list",
  data () {
    return {
      amisScoped: null,
      code: 'userChangeAudit'
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters["account/user"];
    },
  },
  methods:{
    init() {
      if (this.amisScoped) {
        this.amisScoped.unmount();
      }
      this.$nextTick(() => {
        let path = `${process.env.BASE_URL}json/${this.code}.json`
        axios.get(path).then(res=>{
          let amisJSON = res.data
          // this.permission(amisJSON);
          this.amisScoped = this.$amis.embed(
              "#" + this.code,
              amisJSON,
              {},
              {
                // 可以不传，用来实现 ajax 请求
                fetcher: ({ url, method, data, config }) => {
                  console.log(url, method,)
                  if (!data) {
                    data = {};
                  }
                  data["tenantCode"] = sessionStorage.getItem("tenantCode");
                  data["subjectInfoId"] = sessionStorage.getItem("subjectInfoId");
                  data["loginUserId"] = this.userInfo.loginUserId;
                  return request(url, method, data, config);
                },
                theme: "antd",
              }
          );
        })
      });
    },
    permission(data) {
      for (let key in data) {
        if (typeof data[key] === "object") {
          if (Array.isArray(data[key])) {
            for (let i = 0; i < data[key].length; i++) {
              this.permission(data[key][i]);
            }
          } else {
            this.permission(data[key]);
          }
        } else {
          if (data["permission"]) {
            data["className"] = !checkPermission(this.code, data["permission"])
                ? "no-permission"
                : "";
          }
        }
      }
    },
    gotoPage (data) {
      this.$router.push({
        path: 'userRegisterDetails',
        query:{
          id: data.id,
          code: data.enterpriseRegisterType.code === "BREED_ENTERPRISE" ? "T000010_APPLY_TYPE_ENTERPRISE_UPDATE" : "T000010_APPLY_TYPE_FARMERS_UPDATE"
        }
      })
    }
  },
  mounted() {
    this.init();
    let vm = this
    window.gotoPage = function (data){
      vm.gotoPage(data)
    }
  },
  destroyed() {
    this.amisScoped.unmount();
  }
}
</script>

<style scoped>

</style>
